//
//  WithdrawFirstVC.m
//  GasBusiness
//
//  Created by zfc on 2021/8/1.
//

#import "WithdrawFirstVC.h"
#import "WithdrawFirstTopCell.h"
#import "WithdrawFirstRecordCell.h"
#import "WithdrawSecondVC.h"
#import "WithdrawRecordVC.h"
@interface WithdrawFirstVC ()

@property (nonatomic, copy) NSDictionary *userDic;
@end

@implementation WithdrawFirstVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"账户提现";
    [self setUI];
}

- (void)fetchData {
    NSString *url = @"/tiny-shop/v1/member/member/index";
    [[NetWorksTools shared] requestWithMethod:GET url:url params:nil successBlock:^(NSDictionary * _Nonnull response) {
        self.userDic = response[@"data"];
        [self.tableView reloadData];

        } failureBlock:^(NSError * _Nonnull error) {

        }];
}

- (void) setUI {
    self.view.backgroundColor = ColorF5;

    UIButton *withdrawBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [withdrawBtn setTitle:@"提现" forState:UIControlStateNormal];
    [withdrawBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    withdrawBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
    withdrawBtn.cornerRadius = 5;
    withdrawBtn.backgroundColor = ThemeColor;
    [self.view addSubview:withdrawBtn];
    [withdrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-10-kBottomWhiteHeight);
        make.height.mas_equalTo(45);
        make.leading.equalTo(self.view).offset(15);
    }];

    WeakSelf;
    withdrawBtn.block = ^(UIButton *sender) {
        WithdrawSecondVC *vc = [[WithdrawSecondVC alloc] init];
        vc.userDic = weakSelf.userDic;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };

    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.view);
        make.bottom.equalTo(withdrawBtn.mas_top).offset(-10);
    }];

    [self.tableView registerClass:[WithdrawFirstTopCell class] forCellReuseIdentifier:@"WithdrawFirstTopCell"];
    [self.tableView registerClass:[WithdrawFirstRecordCell class] forCellReuseIdentifier:@"WithdrawFirstRecordCell"];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        WithdrawFirstTopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WithdrawFirstTopCell"];
        NSDictionary *account = self.userDic[@"account"];
        cell.dic = account;
        return cell;
    } else {
        WithdrawFirstRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WithdrawFirstRecordCell"];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 150;
    } else {
        return 63;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = ColorF5;
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = ColorF5;
    return view;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 1) { //提现记录
        WithdrawRecordVC *vc = [[WithdrawRecordVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}


@end
